﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ken_WPF_UI.View
{
    /// <summary>
    /// CheckBoxWindow.xaml 的交互逻辑
    /// </summary>
    public partial class CheckBoxWindow : Window
    {

        public CheckBoxWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 获取值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UIElementCollection uIElements =   this.grid.Children;
            StringBuilder sbf = new StringBuilder();
            foreach (var item in uIElements)
            {
                if (item is CheckBox && (item as CheckBox).IsChecked.Value)
                {
                    sbf.Append($"{(item as CheckBox).Content.ToString()},");
                }
            }

            if (sbf.Length > 0)
            {
                sbf.Remove(sbf.Length - 1, 1);
                sbf.Insert(0, "已选择:");
            }
            else
            {
                sbf.Append("未选择");
            }
            MessageBox.Show(sbf.ToString());
        }
    }
}
